//登录界面
var loginBtn=document.querySelector('header .member >div')
loginBtn.onclick=function(){
   var loginDialog=document.querySelector('section.login')
   loginDialog.style.visibility='visible'
}
//关闭登录
var loginClassBtn=document.querySelector('section.login i.icon-close')
loginClassBtn.onclick=function(){
    var loginDialog=document.querySelector('section.login')
    loginDialog.style.visibility='hidden'
}


//登录对话框-蓝色区拖拽
var loginBlueBox =document.querySelector('section.login .menu')
loginBlueBox.onmousedown=function(evt){
        var oldE=evt||window.event
        document.onmousemove=function(evt){
            var e=evt||window.event
            var left=e.clientX-oldE.offsetX
            var top=e.clientY-oldE.offsetY
            if(left<0) left=0
            if(top<0) top=0
            var loginDialog=document.querySelector('section.login .item')
            var maxleft=(window.innerWidth||document.documentElement.clientWidth)-loginDialog.offsetWidth
            var maxtop=(window.innerHeight||document.documentElement.clientHeight)-loginDialog.offsetHeight
            if(left>maxleft) left=maxleft
            if(top>maxtop) top=maxtop
            
            loginDialog.style.position='absolute'
            loginDialog.style.left=left+'px'
            loginDialog.style.top=top+'px'
        }
        document.onmouseup=function(){
            document.onmousemove=null
        }   
}

//验证码倒计时

var num=5
var yzmbtn=document.querySelector('section.login .captcha')
    
yzmbtn.onclick=function(){
    //行为验证码
    var captchaobj=document.querySelector('section.captcha')
    captchaobj.style.visibility='visible'
    //关闭验证码
    document.querySelector('section.captcha i.icon-close').onclick=function(){
        captchaobj.style.visibility='hidden'
    }
    //验证码的拖拽
    var dragBtn=document.querySelector('section.captcha .drag .btn')

    dragBtn.onmousedown=function(){

        document.onmousemove=function(evt){
            var e=evt || window.event
            var left=e.clientX-750-dragBtn.offsetWidth/2
            // var top=e.clientY-dragBtn.offsetHeight/2
            dragBtn.style.left=left +'px'
            document.querySelector('section.captcha .check img:nth-of-type(2)').style.left=left +'px'
            document.onmouseup=function(){
            document.onmousemove=null
            var sum=parseInt(dragBtn.style.left)
            if(sum>=260&&sum<=265){
                yzmbtn.innerText=num+'秒后重发'
                t=setInterval(function(){
            
                    num--
                    yzmbtn.innerText=num+'秒后重发'
                    if(num<=0){
                        clearInterval(t)
                        yzmbtn.innerHTML='请重新发送'
                        yzmbtn.disabled=false
                        num=5
                        return
                    }            
                },1000)
                document.querySelector('section.captcha').style.visibility='hidden'
            }
            
        }
    }
    
    return



    }
  
 
    }
 //表单验证
 var  denglu=document.querySelector('section.login  .submit')
    denglu.onclick=function(){
    var mobile=document.querySelector('.mobile')

    if(mobile.value == '' || mobile.value.length !=11 || !Number(mobile.value)){
        
        document.querySelector('#msg1').innerText='您输入的手机号有误'
        mobile.value=''
    }
    else{
        document.querySelector('#msg1').innerText=''
    }
    var mima=document.querySelector('.password')
    if(mima.value == '' || mima.value.length !=4 || !Number(mima.value)){
        
        document.querySelector('#msg2').innerText='您输入的验证码有误'
        mima.value=''
    }
    else{
        document.querySelector('#msg2').innerText=''
    }
}
